from abc import ABC, abstractclassmethod, abstractmethod
from typing import Dict


class HandlerInterface(ABC):

    @abstractmethod
    def handle(self, **kwargs) -> bool:
        """执行处理逻辑"""

    @abstractclassmethod
    def name(cls) -> str:
        """处理器名称"""

    @abstractmethod
    def init(self):
        """初始化实例"""


class HandlerPool:
    """任务处理器池"""
    _pool: Dict[str, HandlerInterface] = {}

    def init_handlers(self):
        for handler in self._pool.values():
            handler.init()

    def register(self, handler: HandlerInterface):
        self._pool[handler.name()] = handler()

    def get(self, name: str) -> HandlerInterface:
        return self._pool.get(name)


handler_pool = HandlerPool()